<?php
/**
 * Login_Model_Forgotten
 * forgot password implementation
 * 
 * @author Adrian Stolarski
 */
class Login_Model_Forgotten implements Login_Model_Mainable, Login_Model_Getable, 
        Login_Model_Redirectable, Login_Model_Selectable, Login_Model_Setable {
    
    /**
     *
     * @var type $redirect_action
     * redirect action handler
     */
    public $redirect_action;
    /**
     *
     * @var type $check_user_email
     * check user email handler
     */
    public $check_user_email;
    /**
     *
     * @var type $set_user_data
     */
    public $set_user_data;
    
    /**
     * get_user_data()
     * get and validate user data
     * 
     * @param type $value
     * @param type $key
     */
    public function get_user_data($value, $key = null) {
        $variables = array();
        $variables['user_email'] = $value;
        //var_dump($variables);
        //die();
        $this->check_user_email = new Login_Data_Checkuseremail;
        $users_data = $this->check_user_email->main($variables);
        
        //var_dump($users_data);
        //die();
        if(!isset($users_data['user_name']) 
                && ($users_data['user_name'] == '') 
                && is_null($users_data['user_name'])){
            $this->redirect_action = new Login_Data_Forgotredirect;
            $this->redirect_action->main($variables);
        }
    }

    public function main(array $variables = null) {
       //var_dump($variables);
       //die();
       $this->redirect_action($variables);
       $value = $variables['user_email'];
       $this->get_user_data($value, $key);
       $this->set_data($variables);
    }
    
    /**
     * redirect_action()
     * redirect to forgot form
     * 
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        //var_dump($variables);
        //die();
        if(!isset($variables['csrf_token']) && ($variables['csrf_token'] != $_SESSION['csrf_token'])){
            $this->redirect_action = new Login_Data_Forgotredirect;
            $this->redirect_action->main($variables);
        }
    }
    
    public function select_action(array $variables = null) {
        
    }
    
    /**
     * set_data()
     * set new password into database
     * @param array $variables
     */
    public function set_data(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->set_user_data = new Login_Data_Forgotten;
        $this->set_user_data->main($variables);
    }

}
